package com.dianhun.multipledatasources.config;

import com.zaxxer.hikari.HikariDataSource;
import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;

/**
 * @author Administrator
 */
@Configuration
public class DataSourceConfig {

    @Bean
    @Primary
    @ConfigurationProperties("com.dianhun.sharding.datasource.app")
    public DataSourceProperties appDataSourceProperties() {
        return new DataSourceProperties();
    }

    @Bean
    @Primary
    @ConfigurationProperties("com.dianhun.sharding.datasource.app.configuration")
    public HikariDataSource appDataSource() {
        return appDataSourceProperties().initializeDataSourceBuilder().type(HikariDataSource.class).build();
    }

    @Bean
    @ConfigurationProperties("com.dianhun.sharding.datasource.alert")
    public DataSourceProperties alertDataSourceProperties() {
        return new DataSourceProperties();
    }

    @Bean
    @ConfigurationProperties("com.dianhun.sharding.datasource.alert.configuration")
    public HikariDataSource alertDataSource() {
        return alertDataSourceProperties().initializeDataSourceBuilder().type(HikariDataSource.class).build();
    }
}
